var hp = require("./wenzhou_hupai");
var async = require("async");

var seatData = {
	//holds:[3,1,2,5,7,12,23,13,10,24,24,16,5],
	//holds:[1,1,1,3,3,3,5,5,5,24,24,24,17,17,17,18],
	//holds:[7,5,6,5,6,7,1,10,9,18,18,18,2],
	//holds:[2,3,4,6,6,6,16,16,20,20,22,23,24],
	holds:[15,7,31,10,7,6,13,5,4,14,31,7,10],
	//holds:[7,5,6,5,6,7,1,1,1,5,6,28,7],
	//holds:[7,5,6,5,6,7,1,1,1,8],
	//holds:[7,7,1,1],
	//holds:[6,7,8,10,11,12,12,22,23,24],
	//holds:[0,0,7,8,13,14,15],
	//holds:[11,11,11,16],
	//holds:[0,0,0,13,14,15,15],
	countMap:{},
	tingMap:{}
}

for(var i = 0; i < seatData.holds.length; ++i){
	var pai = seatData.holds[i];
	if(seatData.countMap[pai] == null){
		seatData.countMap[pai] = 1;
	}
	else{
		seatData.countMap[pai] ++;
	}
	
}

console.log("behind seatData");
console.log(seatData.countMap);
hp.checkCanTingPaiByBuPai(seatData,8,29);

for(var k in seatData.tingMap)
{
	console.log("牌值 = "+ k);
}

/*

//bagpipe
 var async = function(val, callback) {
 	setTimeout(function() {}, 1000);
 }
 var bagpipe = new Bagpipe(500);
 for (var i=0; i<docs.length; i++) {
	bagpipe.push(async, docs[i].value, function(callback) {
 });
 }

 //async
 var q = async.queue(function(task, callback) {
 setTimeout(function() {
 	log.info(task);
 	callback(null, {});}, 5000);}, 10);
 	q.drain = function() {
 	log.info("finish");}
 	for (var i=0; i<100; i++) {
 		q.push(i, function(err, data) {
 	});
 }
*/
//function exec()
//{
 //async.series({
	//one: function(callback){
		//callback(null, 1);
	//},
	//two: function(callback){
		//callback(null, 2);
	//}
//},function(err, results) {
	//console.log(results);
//});
//}

//async1.exec();


function seriesSaveToDB(game,roomInfo,dbresult,roomId,results,userId)
{
 async.series({
            store_game: function(callback)
            {
                //db.create_game(roomInfo.uuid,game.gameIndex,game.baseInfoJson,callback);
				//update_game(game,roomId);
				console.log("store_game");
				callback(null,1);
            },
            update_game: function(callback)
            {
				//wait(game,roomInfo);
				console.log("update_game");
				callback(null,2);
            },
            wait: function(callback)
            {
				//update_story(game,roomInfo)
                //callback(null, 3);
				console.log("wait");
				callback(null,3);
            },
            update_story: function(callback)
            {
                //release(game,roomInfo);
                //callback(null, 4);
				setTimeout(function(){},2000);
				console.log("update_story");
				callback(null,4);
            },
            release: function(callback)
            {
                //userMgr.kickAllInRoom(roomId);
                //roomMgr.destroy(roomId);
                //db.archive_games(roomInfo.uuid);
                //callback(null, 5);
				console.log("release");
				callback(null,5);
            }
        },function(err, results) {
            console.log(results);
        });
}

var game = {};
var roomInfo = {};
var dbresult = [0,0,0,0];
var roomId = 1;
var results = true;
var userId = 146;
seriesSaveToDB(game,roomInfo,dbresult,roomId,results,userId);